package es.udc.emarketapp.emarket.test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

import es.udc.emarketapp.emarket.model.product.dao.SQLProductDAO;
import es.udc.emarketapp.emarket.model.product.dao.SQLProductDAOFactory;
import es.udc.emarketapp.emarket.model.product.vo.ProductVO;

import es.udc.fbellas.j2ee.util.sql.SimpleDataSource;



public final class PruebaProduct {
	
    public static void main (String[] args) throws Exception {
    	
   /* 	
    	TestCase test = new ProductDAOTest();
    	
    	((ProductDAOTest) test).createFindByIdAndRemoveProduct();
    	((ProductDAOTest) test).cerateFindSellerAndUpdate();
    	
    */	
     	
    	Connection connection = null;
    	Statement statement = null;
    		
    	try {	
        
    		SimpleDataSource dataSource = new SimpleDataSource();    
    	
    		connection = dataSource.getConnection();

    		    		
           //Creamos un SQLProductDAO
    		SQLProductDAO productDAO = SQLProductDAOFactory.getDAO();
    		
    		
    		
    	   //Prueba create +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    	   //Creamos el productoVO 
    		byte[] img = null; 
  
    		ProductVO productVO = new ProductVO("user5", new Long(2), "chocolate en rama", "Chocolate suizo con leche en rama", "spain", new Long(15), img, 3.50, 0.400, true);
    		
    		productDAO.create(connection, productVO);
    	
    		
    		
    	/*
    	  	//Pueba exists +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    	 
    		if(productDAO.exists(connection, new Long(10))){
    			System.out.println("existe");
    		}else{ System.out.println("no existe");}

    	*/
    		
    		
    	/*
    	  	//Prueba findById ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    	  	 
    		ProductVO productoVO = productDAO.findById(connection, new Long(5));
    		
    		System.out.println(productoVO.toString());
    	*/	
    		
    	/*
    	  //Prueba invalidate +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    	   productDAO.invalidate(connection, new Long(5));  	
    	*/
    	
    		
    		
    	/*	
    	  //Prueba isValid +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    		if(productDAO.isValid(connection, new Long(6))){
    			System.out.println("es valido");
    		}else{ System.out.println("no es valido");}
    	*/
    		
    	
    		
    	/*
    		//Prueba findByKeywords +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    		 
    		// Get value objects in groups of 2. 
    		 int startIndex = 1;
    		 int groupCount = 2;
    		 List<ProductVO> productVOs;
    		 do {
    			  productVOs  = productDAO.findByKeywords(connection, "casa choco agua", startIndex, groupCount);
    		      // Print value objects. 
    		      for (ProductVO a : productVOs) {
    		          System.out.println(a);
    		      }
    		   
    		      System.out.println("--------------------------------");
    		      startIndex += groupCount;
    		 } while (productVOs.size() == groupCount);
        */
    		
    		
        /*	
        		//Prueba findByKeywordsAndCategory +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        		 
        		// Get value objects in groups of 2. 
        		 int startIndex = 1;
        		 int groupCount = 2;
        		 List<ProductVO> productVOs;
        		 do {
        			  productVOs  = productDAO.findByKeywordsAndCategory(connection, 
        					  "me como el chocolate con agua", new Long(6),
        					  startIndex, groupCount);
        		      // Print value objects. 
        		      for (ProductVO a : productVOs) {
        		          System.out.println(a);
        		      }
        		   
        		      System.out.println("--------------------------------");
        		      startIndex += groupCount;
        		 } while (productVOs.size() == groupCount);
        */ 
            
    		
    	/*	
    		//Prueba findByName +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    		 
    		// Get value objects in groups of 2. 
    		 int startIndex = 1;
    		 int groupCount = 2;
    		 List<ProductVO> productVOs;
    		 do {
    			  productVOs  = productDAO.findByName(connection, "agua", startIndex, groupCount);
    		      // Print value objects. 
    		      for (ProductVO a : productVOs) {
    		          System.out.println(a);
    		      }
    		   
    		      System.out.println("--------------------------------");
    		      startIndex += groupCount;
    		 } while (productVOs.size() == groupCount);
       */
    	
    	/*	
    		
    		//Prueba findByCategory +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   		 
    		// Get value objects in groups of 2. 
    		 int startIndex = 1;
    		 int groupCount = 2;
    		 List<ProductVO> productVOs;
    		 do {
    			  productVOs  = productDAO.findByCategory(connection, new Long(6), startIndex, groupCount);
    		      // Print value objects. 
    		      for (ProductVO a : productVOs) {
    		          System.out.println(a);
    		      }
    		   
    		      System.out.println("--------------------------------");
    		      startIndex += groupCount;
    		 } while (productVOs.size() == groupCount);
    	
    	*/
    	
    /*			
    		//Prueba findBySeller ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    		 
    		// Get value objects in groups of 2. 
    		 int startIndex = 1;
    		 int groupCount = 2;
    		 List<ProductVO> productVOs;
    		 do {
    	    		
    			  productVOs  = productDAO.findBySeller(connection, "user6", startIndex, groupCount);
    		      // Print value objects. 
    		      for (ProductVO a : productVOs) {
    		          System.out.println(a);
    		      }
    		   
    		      System.out.println("--------------------------------");
    		      startIndex += groupCount;
    		 } while (productVOs.size() == groupCount);
    */	
    		
    	
    	/*			
    		//Prueba findByOrigin ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    		 
    		// Get value objects in groups of 2. 
    		 int startIndex = 1;
    		 int groupCount = 2;
    		 List<ProductVO> productVOs;
    		 do {
    	    		
    			  productVOs  = productDAO.findByOrigin(connection, "spain", startIndex, groupCount);
    		      // Print value objects. 
    		      for (ProductVO a : productVOs) {
    		          System.out.println(a);
    		      }
    		   
    		      System.out.println("--------------------------------");
    		      startIndex += groupCount;
    		 } while (productVOs.size() == groupCount);
    	*/
    		
    			
    		
    		
    	
    	/* 
    	 
    	    //Prueba update ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    	
    		String nomProd = "Agua tynant 2l"; 
    		String descripcion = "un agua de mineralización débil, baja en sodio y rica en calcio, procedente de un manantial de las montañas Cambrian, en Bethania, en corazón del País de Gales.";
    		Long idCat = new Long(6);
    		Long idProd = new Long(3); 
    		String idVendedor = "user6"; 
    		byte[] imagen = null; 
    		String paisOrigen = "gales";
    		double peso = 0.5;
    		double precio = 3.5; 
    		Long udsDisp = new Long(10);
    		Boolean valido = true;
    		
    		ProductVO productVO = new ProductVO(idProd,  idVendedor,  idCat,  
    				nomProd, descripcion,  paisOrigen,  udsDisp, imagen,
    				 precio,  peso, valido);
    		
    		productDAO.update(connection, productVO);
    	   		
    	*/
    		
    		
    	/*
 			//Prueba remove ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 			
    		productDAO.remove(connection, new Long(8));
    	*/	
    		
    		
    		
    		
    		 
        } finally {
            try {
                 if (connection != null) {
                     connection.close();
                 }
            } catch (SQLException e) {
                 e.printStackTrace();
            }
        } // try
    } // main
} // class